package cn.JHai.rbac.controller;

import cn.JHai.rbac.RequiredPermission;

import cn.JHai.rbac.domain.Customertracehistory;
import cn.JHai.rbac.service.CustomerTraceHistoryService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.JHai.rbac.query.PageResult;
import cn.JHai.rbac.query.QueryObject;
import org.springframework.ui.Model;

@Controller
@RequestMapping("customerTraceHistory")
public class CustomerTraceHistoryController {


    @Autowired
    private CustomerTraceHistoryService customerTraceHistoryService;
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    @RequiredPermission({"客户跟进历史添加/更新","customerTraceHistory:saveOrUpdate"})
    public JSONObject saveOrUpdate(Customertracehistory history, Long customer_id) {
        System.out.println(customer_id);
        System.out.println(history);
        customerTraceHistoryService.saveOrUpdata(history, customer_id);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("success", true);
        return jsonObject;
    }



    @RequestMapping("/list")
    @RequiredPermission({"客户跟进历史列表","customerTraceHistory:list"})
    public String list(QueryObject queryObject , Model model){
        PageResult result = customerTraceHistoryService.query(queryObject);
        result.setCurrentKeyword(queryObject.getKeyword());
        model.addAttribute("result",result);
        return "/customerTraceHistory/list";
    }
}
